package com.appistry.maven.plugin.far.remote.ssh;

import java.io.File;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class SftpCommandIT {

	private static final String TEMP_DEST_TEST_DIR = "tempDestTestDir";

	private Sftp sftp;
	private SshConfig sshConfig;
	private Command command;

	private SshExec sshExec; // run ssh commands to check files were transferred

	@Before
	public void setUp() throws Exception {
		sshConfig = new SshConfig(SshConstants.HOST, SshConstants.PORT,
				new SshUserInfo(SshConstants.USER, SshConstants.PASSWORD, true));
		sshExec = new SshExec(sshConfig);
		sshExec.executeCommand("mkdir " + TEMP_DEST_TEST_DIR);
	}

	@After
	public void tearDown() throws Exception {
		// this is dangerous. But is necessary for cleanup
		sshExec.executeCommand("rm -rf " + TEMP_DEST_TEST_DIR);
		sshExec = null;
	}

	@Ignore
	@Test
	public void testSftpLargeFile() throws Exception {
		File largeFile = new File("target" + File.separator + "classes",
				"largefile.zip");

		sftp = new Sftp();
		sftp.setSshConfig(sshConfig);
		sftp.setTransferType(Sftp.TYPE.put);
		sftp.setSrcFilename(largeFile.getAbsolutePath());
		sftp.setDestFilename(TEMP_DEST_TEST_DIR + File.separator
				+ largeFile.getName());

		command = new SftpCommand(sftp);
		command.execute();
	}
}
